from django.shortcuts import render_to_response
from django.template import RequestContext

import models

def get_config():
    try:
        return models.Config.objects.get(id = 1)
    except :
        return None
    
#    except ObjectDoesNotExist, models.Config.DoesNotExist:
#    config = None

def index (request):
    return render_to_response('index.html', { 'config': get_config(), }, context_instance=RequestContext(request))

#    if (config):
#        return render_to_response('index.html', { 'config': config, }, context_instance=RequestContext(request))
#    else:
#        return render_to_response('error.html', { 'errors': ('No hay una config valid', ), } )

        


"""
from django.template import RequestContext, loader

from django.contrib.auth.decorators import login_required
from forms import PerfilForm, UserForm

@login_required
def editar_perfil(request):

    if request.method == 'POST':
        # formulario enviado
        user_form = UserForm(request.POST, instance=request.user)
        perfil_form = PerfilForm(request.POST, instance=request.user.perfil)

        if user_form.is_valid() and perfil_form.is_valid():
            # formulario validado correctamente
            user_form.save()
            perfil_form.save()
            return HttpResponseRedirect('/formulario-guardado/')

    else:
        # formulario inicial
        user_form = UserForm(instance=request.user)
        perfil_form = PerfilForm(instance=request.user.perfil)

    return render_to_response('editar_perfil.html', { 'user_form': user_form,  'perfil_form': perfil_form }, context_instance=RequestContext(request))
"""